
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_member_blog_comments.
	''' </summary>
	Public Partial Class view_member_blog_comments
		Inherits BaseWebPage
		Private blogID As Integer
		Private memberID As Integer
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.VIEW_BLOG_COMMENTS_PAGE;


			If LoggedUser = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			If Request.Params("id") = Nothing OrElse Request.Params("id") = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			If Request.Params("usr") = Nothing OrElse Request.Params("usr") = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			Me.RegisterStartupScript("resizeImages", Constants.RESIZE_BLOG_IMAGE_SCRIPT)
			Me.pageTemplate.onLoadScript = "resizeImages()"

			Me.initPageTitles(Constants.VIEW_MEMBER_BLOG_COMMENTS, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			blogID = Convert.ToInt32(Request.Params("id"))
			memberID = Convert.ToInt32(Request.Params("usr"))
			Dim member As User = Users.GetUserByID(memberID)

			If member <> Nothing AndAlso member.ID <> LoggedUser.ID Then
				ucMemberShortcut.UserID = member.ID
			Else
				trUserShortCut.Visible = False
			End If

			Dim blog As Blog = Messages.GetUserBlog(member.ID, blogID)
			Dim blogComments As ArrayList = Messages.GetUserBlogEntries(blogID)
			Dim curBlogDate As DateTime = blog.DateSent
			lblDate.Text = curBlogDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + ", " + curBlogDate.Year
			lblSubject.Text = Server.HtmlEncode(blog.Subject)
			litBlogBody.Text = Me.initBlogMessage(blog.Body)
			lblTimePosted.Text = curBlogDate.ToShortTimeString()
			lblCommentsCount.Text = blogComments.Count.ToString() + " " + "Comment"
			If blogComments.Count <> 1 Then
				lblCommentsCount.Text += "s"
			End If
			litName.Text = member.Name + "'s "
			hlReturnToBlog.Text = (Me.GetPageConstText(htPageConstants, "CONST_ReturnLink_TEXT")).Replace("[PARAM]", member.Name)
			hlReturnToBlog.NavigateUrl = "../" + Constants.VIEW_MEMBER_BLOG + "?id=" + memberID

			' the check is removed by maz's request
			Dim bIsLoggedUserFriendOfBlogOwner As Boolean = True
			'member.DirectFriends.Contains(LoggedUser.ID);
			lbAddComment.Visible = bIsLoggedUserFriendOfBlogOwner
			lblNotInFriendsListMsg.Visible = Not bIsLoggedUserFriendOfBlogOwner

			If Not IsPostBack Then
				BindGrid()
			End If
		End Sub
		Protected Function CreateDataSource() As ICollection
			Dim usr As BO.User = Users.GetUserByID(memberID)

			Dim dt As New DataTable()
			Dim curBlogDate As DateTime

			' List user's inbox messages
			Dim blogEntries As ArrayList = Messages.GetUserBlogEntries(blogID)

			If blogEntries.Count = 0 Then
				lblNoBlog.Visible = True
			Else
				lblNoBlog.Visible = False
			End If
			Dim dr As DataRow
			dt.Columns.Add(New DataColumn("SenderID", GetType(Integer)))
			dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
			dt.Columns.Add(New DataColumn("SenderImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Date", GetType(String)))
			dt.Columns.Add(New DataColumn("Time", GetType(String)))
			dt.Columns.Add(New DataColumn("Body", GetType(String)))
			dt.Columns.Add(New DataColumn("BlogID", GetType(String)))
			dt.Columns.Add(New DataColumn("SenderNameFull", GetType(String)))
			dt.Columns.Add(New DataColumn("OnClickJS", GetType(String)))
			'dt.Columns.Add(new DataColumn("Subject", typeof(string)));	

			Dim temp As UserPicture
			' List user's inbox messages
			For Each blog As Blog In blogEntries
				dr = dt.NewRow()
				curBlogDate = blog.DateSent
				dr(0) = blog.SenderID
				dr(1) = getBeginning(HttpUtility.HtmlEncode(blog.Sender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
				dr(8) = blog.Sender.Name
				temp = blog.Sender.DefaultPicture
				If temp <> Nothing Then
					dr(2) = Pictures.GetPictureSrcFullURL(temp, True, "../")
				Else
					dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
				End If

				dr(3) = Users.ComposeMemeberLink(blog.Sender)
				dr(9) = Users.ComposeMemeberLinkOnClickJS(blog.Sender, trUserCanceledMessage)

				dr(4) = curBlogDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + ", " + curBlogDate.Year
				dr(5) = curBlogDate.ToShortTimeString()

				dr(6) = Me.initBlogMessage(blog.Body)
				dr(7) = blog.ID
				'dr[8] = Server.HtmlEncode(blog.Subject);

				dt.Rows.Add(dr)
			Next
			Dim dv As New DataView(dt)
			Return dv
		End Function
		Protected Sub BindGrid()
			dgMessages.DataSource = CreateDataSource()
			dgMessages.DataBind()
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()

		End Sub
#End Region

		Protected Sub lbAddComment_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If LoggedUser.DirectFriends.Contains(memberID) Then
				Response.Redirect(Constants.POST_MEMBER_BLOG_COMMENT + "?id=" + blogID + "&usr=" + memberID)
			Else
				lblNoBlog.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgNoFriends_TEXT")
				lblNoBlog.Visible = True
				trBlog.Visible = False
				dgMessages.Visible = False
			End If
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace







